package com.zjut.azhen.DBDesign.service;

import com.zjut.azhen.DBDesign.bean.Report;
import com.zjut.azhen.DBDesign.bean.Students;
import com.zjut.azhen.DBDesign.mapping.ScoreMapper;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ScoreService {
        private final ScoreMapper scoreMapper;
    public ScoreService(ScoreMapper scoreMapper){
        this.scoreMapper=scoreMapper;
    }



    public List<Map<String,Object>> getScoreYearsBySno(String sno){

        List<Map<String,Object>> list1=new ArrayList<>();

        List<Report> list=scoreMapper.getScoreYearsBySno(sno);

        for(Report report:list){
            Map<String,Object> map=new HashMap<>();
            map.put("term",report.getTerm());
            map.put("score",report.getScore());
            list1.add(map);
        }
        return list1;
    }

    public List<Map<String,Object>> getRankedScore(String term,String mno){
        List<Map <String,Object>> list1=new ArrayList<>();
        Integer rank=0;
        List<Report> list=scoreMapper.getRankedScore(term,mno);
        for (Report report: list) {
            Map<String,Object> map=new HashMap<>();
            rank++;
            map.put("rank",rank);
            map.put("report",report);
            list1.add(map);
        }
        return list1;

    }

    public Map<String,Object> getCredit(String sno){
        Map<String,Object> map=new HashMap<>(3);
        Students students=scoreMapper.getCreditBySno(sno);
        map.put("credit",students.getsCredit());
        map.put("sno",students.getSno());
        map.put("sname",students.getSname());


       return map;
    }
    public List<Report> getScore(String sno){
        return scoreMapper.getScoreBySno(sno);
    }

    public Report getAvgScoreBySno(String sno) {
        return scoreMapper.getAvgScoreBySno(sno);
    }

//    public Map<Integer,Report> getRankedScore(){
//
//    }
//
//    public List<Report> getScoreById{}
}
